/*
* Alexey Danchuk
* This software is an implementation of the first task from tasks.pdf
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Program to find first N prime numbers.
 * 
 * @version	1.01 27 January 2013
 * @author	Alexey Danchuk
 */
public class PrimeNumbers {

	/**
	 * Method checks whether the number is prime or not.
	 * The original source of the information:
	 * http://en.wikipedia.org/wiki/Prime_number
	 *
	 * @param number - our N, which is given by the condition
	 * @return true - number is prime, false - not prime
	 */
	public static boolean isPrimeNumber(int number) {
		boolean primeNumber = true; // the initial state of the flag
		int measure = (int) Math.sqrt(number);
		/* Check to see if the number is prime. */
		for (int i = 2; i <= measure; i++) {
			if (number % i == 0) {
				primeNumber = false;
				break;
			}
		}
		return primeNumber;
	}
	
	/**
	* Method for processing our prime numbers algorithm.
	*
	* @param number - verification number
	*/
	public static void process(int number) {
		if (isPrimeNumber(number)) {
			System.out.println(number);
		}
	}
	
	/**
	* Method for output prime numbers.
	*
	*@param inputNumber - number from user
	*/
	public static void output(int inputNumber) {
		for (int i = 2; i <= inputNumber; i++) {
			 process(i);
		}
	}
	
	/**
	* Method for input data.
	*
	* @throws Exception
	*/
	public static int input() throws Exception {
		BufferedReader inputStream = new BufferedReader(new InputStreamReader(
				                                            System.in));
		System.out.println("Enter the number for output all prime numbers:");
		/*for converting the parses the string argument and define 'inNumber'
		  as an integer.*/
		int inNumber = Integer.parseInt(inputStream.readLine());
		return inNumber;
	}

	/**
	 * Main method. Entry point into the program.
	 * 
	 * @param args - command-Line arguments, this allows the user to specify
	 * configuration information when the application is launched.
	 */
	public static void main(String[] args) {
		try {
			int inputNumber = input();
			output(inputNumber);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
